package sean.org;

import java.lang.reflect.Method;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {

	@Pointcut("@annotation(sean.org.Action)")
	public void annotationPointCut(){};
	
	@Pointcut("execution(* sean.org.DemoMethodService.*(..))")
	public void annotationPointCut1(){};
	
//	@After("annotationPointCut()")
	@Before("@annotation(sean.org.Action)")
	public void after(JoinPoint joinPoint){
		MethodSignature signature= (MethodSignature) joinPoint.getSignature();
		Method method = signature.getMethod();
		Action action = method.getAnnotation(Action.class);
		System.out.println("注解上拦截 "+action.name());
	}
	
	@Before("execution(* sean.org.DemoMethodService.*(..))")
//	@After("annotationPointCut1()")
	public void before(JoinPoint joinPoint){
		MethodSignature signature= (MethodSignature) joinPoint.getSignature();
		Method method = signature.getMethod();
		System.out.println("方法上拦截 "+method.getName());
	}
}
